import React, { Component } from 'react'
import PubSub from 'pubsub-js'
import axios from 'axios';
import app from '../../App.module.css';
export default class index extends Component {
    search = () => {
       const { inputValue:{value} } = this
       if(!value.trim()) return alert('请输入搜索内容')
       PubSub.publish('MY TOPIC',{step:'loading'})
       axios.get(`/api1/search/users?q=${value}`).then((res) => { 
        console.log(res);
        PubSub.publish('MY TOPIC',{data:res.data.items,step:'result'})
        },error=>{
            window.confirm('请求出错了')
        })
    }
  render() {
    return (
        <div className={app.header}>
            <h2>Search Github Users</h2>
            <input type="text" ref={e=>this.inputValue = e} placeholder='enter the name you search' /><button onClick={this.search}>Search</button>
        </div>
    )
  }
}
